#ifndef __GAF_DEVICECODE_H__
#define __GAF_DEVICECODE_H__

#include "GAF_Define.h"

enum GAF_EKeyCode
{
	GAF_KEY_UNKNOWN			= 0,

        /** @name ASCII mapped keys
         *  The keyboard have been cleverly chosen to map to ASCII
         */
        /*@{*/
	GAF_KEY_FIRST			= 0,
	GAF_KEY_BACKSPACE		= 8,		//+ 退格
	GAF_KEY_TAB			= 9,		//+ "TAB"
	GAF_KEY_CLEAR			= 12,
	GAF_KEY_RETURN			= 13,		//+ 回车
	GAF_KEY_PAUSE			= 19,
	GAF_KEY_ESCAPE			= 27,		//+ "ESC"
	GAF_KEY_SPACE			= 32,		//+ " "
	GAF_KEY_EXCLAIM			= 33,		//- "!"
	GAF_KEY_QUOTEDBL		= 34,
	GAF_KEY_HASH			= 35,
	GAF_KEY_DOLLAR			= 36,		//- "$"
	GAF_KEY_AMPERSAND		= 38,
	GAF_KEY_QUOTE			= 39,		//+ "."
	GAF_KEY_LEFTPAREN		= 40,		//- "("
	GAF_KEY_RIGHTPAREN		= 41,		//- ")"
	GAF_KEY_ASTERISK		= 42,		//- "*"
	GAF_KEY_PLUS			= 43,		//- "+"
	GAF_KEY_COMMA			= 44,		//- ","
	GAF_KEY_MINUS			= 45,		//+ "-"
	GAF_KEY_PERIOD			= 46,
	GAF_KEY_SLASH			= 47,		//- "/"
	GAF_KEY_0			= 48,		//+ "0"
	GAF_KEY_1			= 49,		//+ "1"
	GAF_KEY_2			= 50,		//+ "2"
	GAF_KEY_3			= 51,		//+ "3"
	GAF_KEY_4			= 52,		//+ "4"
	GAF_KEY_5			= 53,		//+ "5"
	GAF_KEY_6			= 54,		//+ "6"
	GAF_KEY_7			= 55,		//+ "7"
	GAF_KEY_8			= 56,		//+ "8"
	GAF_KEY_9			= 57,		//+ "9"
	GAF_KEY_COLON			= 58,
	GAF_KEY_SEMICOLON		= 59,		//+ ","
	GAF_KEY_LESS			= 60,
	GAF_KEY_EQUALS			= 61,		//+ "="
	GAF_KEY_GREATER			= 62,
	GAF_KEY_QUESTION		= 63,
	GAF_KEY_AT			= 64,
	/* 
	   Skip uppercase letters
	 */
	GAF_KEY_LEFTBRACKET		= 91,		//+ "["
	GAF_KEY_BACKSLASH		= 92,		//+ "\"
	GAF_KEY_RIGHTBRACKET		= 93,		//+ "]"
	GAF_KEY_CARET			= 94,
	GAF_KEY_UNDERSCORE		= 95,
	GAF_KEY_BACKQUOTE		= 96,		//+ "`"
	GAF_KEY_A			= 97,		//+ "A"
	GAF_KEY_B			= 98,		//+ "B"
	GAF_KEY_C			= 99,		//+ "C"
	GAF_KEY_D			= 100,		//+ "D"
	GAF_KEY_E			= 101,		//+ "E"
	GAF_KEY_F			= 102,		//+ "F"
	GAF_KEY_G			= 103,		//+ "G"
	GAF_KEY_H			= 104,		//+ "H"
	GAF_KEY_I			= 105,		//+ "I"
	GAF_KEY_J			= 106,		//+ "J"
	GAF_KEY_K			= 107,		//+ "K"
	GAF_KEY_L			= 108,		//+ "L"
	GAF_KEY_M			= 109,		//+ "M"
	GAF_KEY_N			= 110,		//+ "N"
	GAF_KEY_O			= 111,		//+ "O"
	GAF_KEY_P			= 112,		//+ "P"
	GAF_KEY_Q			= 113,		//+ "Q"
	GAF_KEY_R			= 114,		//+ "R"
	GAF_KEY_S			= 115,		//+ "S"
	GAF_KEY_T			= 116,		//+ "T"
	GAF_KEY_U			= 117,		//+ "U"
	GAF_KEY_V			= 118,		//+ "V"
	GAF_KEY_W			= 119,		//+ "W"
	GAF_KEY_X			= 120,		//+ "X"
	GAF_KEY_Y			= 121,		//+ "Y"
	GAF_KEY_Z			= 122,		//+ "Z"
	GAF_KEY_DELETE			= 127,		//+ 删除
	/* End of ASCII mapped keys */
	/*@}*/

	/** @name International keyboard */
	/*@{*/
	GAF_KEY_WORLD_0			= 160,		/* 0xA0 */
	GAF_KEY_WORLD_1			= 161,
	GAF_KEY_WORLD_2			= 162,
	GAF_KEY_WORLD_3			= 163,
	GAF_KEY_WORLD_4			= 164,
	GAF_KEY_WORLD_5			= 165,
	GAF_KEY_WORLD_6			= 166,
	GAF_KEY_WORLD_7			= 167,
	GAF_KEY_WORLD_8			= 168,
	GAF_KEY_WORLD_9			= 169,
	GAF_KEY_WORLD_10		= 170,
	GAF_KEY_WORLD_11		= 171,
	GAF_KEY_WORLD_12		= 172,
	GAF_KEY_WORLD_13		= 173,
	GAF_KEY_WORLD_14		= 174,
	GAF_KEY_WORLD_15		= 175,
	GAF_KEY_WORLD_16		= 176,
	GAF_KEY_WORLD_17		= 177,
	GAF_KEY_WORLD_18		= 178,
	GAF_KEY_WORLD_19		= 179,
	GAF_KEY_WORLD_20		= 180,
	GAF_KEY_WORLD_21		= 181,
	GAF_KEY_WORLD_22		= 182,
	GAF_KEY_WORLD_23		= 183,
	GAF_KEY_WORLD_24		= 184,
	GAF_KEY_WORLD_25		= 185,
	GAF_KEY_WORLD_26		= 186,
	GAF_KEY_WORLD_27		= 187,
	GAF_KEY_WORLD_28		= 188,
	GAF_KEY_WORLD_29		= 189,
	GAF_KEY_WORLD_30		= 190,
	GAF_KEY_WORLD_31		= 191,
	GAF_KEY_WORLD_32		= 192,
	GAF_KEY_WORLD_33		= 193,
	GAF_KEY_WORLD_34		= 194,
	GAF_KEY_WORLD_35		= 195,
	GAF_KEY_WORLD_36		= 196,
	GAF_KEY_WORLD_37		= 197,
	GAF_KEY_WORLD_38		= 198,
	GAF_KEY_WORLD_39		= 199,
	GAF_KEY_WORLD_40		= 200,
	GAF_KEY_WORLD_41		= 201,
	GAF_KEY_WORLD_42		= 202,
	GAF_KEY_WORLD_43		= 203,
	GAF_KEY_WORLD_44		= 204,
	GAF_KEY_WORLD_45		= 205,
	GAF_KEY_WORLD_46		= 206,
	GAF_KEY_WORLD_47		= 207,
	GAF_KEY_WORLD_48		= 208,
	GAF_KEY_WORLD_49		= 209,
	GAF_KEY_WORLD_50		= 210,
	GAF_KEY_WORLD_51		= 211,
	GAF_KEY_WORLD_52		= 212,
	GAF_KEY_WORLD_53		= 213,
	GAF_KEY_WORLD_54		= 214,
	GAF_KEY_WORLD_55		= 215,
	GAF_KEY_WORLD_56		= 216,
	GAF_KEY_WORLD_57		= 217,
	GAF_KEY_WORLD_58		= 218,
	GAF_KEY_WORLD_59		= 219,
	GAF_KEY_WORLD_60		= 220,
	GAF_KEY_WORLD_61		= 221,
	GAF_KEY_WORLD_62		= 222,
	GAF_KEY_WORLD_63		= 223,
	GAF_KEY_WORLD_64		= 224,
	GAF_KEY_WORLD_65		= 225,
	GAF_KEY_WORLD_66		= 226,
	GAF_KEY_WORLD_67		= 227,
	GAF_KEY_WORLD_68		= 228,
	GAF_KEY_WORLD_69		= 229,
	GAF_KEY_WORLD_70		= 230,
	GAF_KEY_WORLD_71		= 231,
	GAF_KEY_WORLD_72		= 232,
	GAF_KEY_WORLD_73		= 233,
	GAF_KEY_WORLD_74		= 234,
	GAF_KEY_WORLD_75		= 235,
	GAF_KEY_WORLD_76		= 236,
	GAF_KEY_WORLD_77		= 237,
	GAF_KEY_WORLD_78		= 238,
	GAF_KEY_WORLD_79		= 239,
	GAF_KEY_WORLD_80		= 240,
	GAF_KEY_WORLD_81		= 241,
	GAF_KEY_WORLD_82		= 242,
	GAF_KEY_WORLD_83		= 243,
	GAF_KEY_WORLD_84		= 244,
	GAF_KEY_WORLD_85		= 245,
	GAF_KEY_WORLD_86		= 246,
	GAF_KEY_WORLD_87		= 247,
	GAF_KEY_WORLD_88		= 248,
	GAF_KEY_WORLD_89		= 249,
	GAF_KEY_WORLD_90		= 250,
	GAF_KEY_WORLD_91		= 251,
	GAF_KEY_WORLD_92		= 252,
	GAF_KEY_WORLD_93		= 253,
	GAF_KEY_WORLD_94		= 254,
	GAF_KEY_WORLD_95		= 255,		/* 0xFF */
	/*@}*/

	/** @name Numeric keypad */
	/*@{*/
	GAF_KEY_KP_0			= 256,
	GAF_KEY_KP_1			= 257,
	GAF_KEY_KP_2			= 258,
	GAF_KEY_KP_3			= 259,
	GAF_KEY_KP_4			= 260,
	GAF_KEY_KP_5			= 261,
	GAF_KEY_KP_6			= 262,
	GAF_KEY_KP_7			= 263,
	GAF_KEY_KP_8			= 264,
	GAF_KEY_KP_9			= 265,
	GAF_KEY_KP_PERIOD		= 266,
	GAF_KEY_KP_DIVIDE		= 267,
	GAF_KEY_KP_MULTIPLY		= 268,
	GAF_KEY_KP_MINUS		= 269,
	GAF_KEY_KP_PLUS			= 270,
	GAF_KEY_KP_ENTER		= 271,
	GAF_KEY_KP_EQUALS		= 272,
	/*@}*/

	/** @name Arrows + Home/End pad */
	/*@{*/
	GAF_KEY_UP			= 273,
	GAF_KEY_DOWN			= 274,
	GAF_KEY_RIGHT			= 275,
	GAF_KEY_LEFT			= 276,
	GAF_KEY_INSERT			= 277,
	GAF_KEY_HOME			= 278,
	GAF_KEY_END			= 279,
	GAF_KEY_PAGEUP			= 280,
	GAF_KEY_PAGEDOWN		= 281,
	/*@}*/

	/** @name Function keys */
	/*@{*/
	GAF_KEY_F1			= 282,		//+ "F1"
	GAF_KEY_F2			= 283,		//+ "F2"
	GAF_KEY_F3			= 284,		//+ "F3"
	GAF_KEY_F4			= 285,		//+ "F4"
	GAF_KEY_F5			= 286,		//+ "F5"
	GAF_KEY_F6			= 287,		//+ "F6"
	GAF_KEY_F7			= 288,		//+ "F7"
	GAF_KEY_F8			= 289,		//+ "F8"
	GAF_KEY_F9			= 290,		//+ "F9"
	GAF_KEY_F10			= 291,		//+ "F10"
	GAF_KEY_F11			= 292,		//+ "F11"
	GAF_KEY_F12			= 293,		//+ "F12"
	GAF_KEY_F13			= 294,		//+ "F13"
	GAF_KEY_F14			= 295,		//+ "F14"
	GAF_KEY_F15			= 296,		//+ "F15"
	/*@}*/

	/** @name Key state modifier keys */
	/*@{*/
	GAF_KEY_NUMLOCK			= 300,
	GAF_KEY_CAPSLOCK		= 301,		//+ 大写锁定
	GAF_KEY_SCROLLOCK		= 302,
	GAF_KEY_RSHIFT			= 303,
	GAF_KEY_LSHIFT			= 304,		//+ 左Shift
	GAF_KEY_RCTRL			= 305,
	GAF_KEY_LCTRL			= 306,
	GAF_KEY_RALT			= 307,
	GAF_KEY_LALT			= 308,
	GAF_KEY_RMETA			= 309,
	GAF_KEY_LMETA			= 310,
	GAF_KEY_LSUPER			= 311,		/**< Left "Windows" key */
	GAF_KEY_RSUPER			= 312,		/**< Right "Windows" key */
	GAF_KEY_MODE			= 313,		/**< "Alt Gr" key */
	GAF_KEY_COMPOSE			= 314,		/**< Multi-key compose key */
	/*@}*/

	/** @name 杂项功能键 */
	/*@{*/
	GAF_KEY_HELP			= 315,
	GAF_KEY_PRINT			= 316,		//+ 打印键
	GAF_KEY_SYSREQ			= 317,
	GAF_KEY_BREAK			= 318,
	GAF_KEY_MENU			= 319,		//+ 快捷菜单键
	GAF_KEY_POWER			= 320,		/**< Power Macintosh power key */
	GAF_KEY_EURO			= 321,		/**< Some european keyboards */
	GAF_KEY_UNDO			= 322,		/**< Atari keyboard has Undo */
	/*@}*/

	GAF_KEY_MAX,
};

enum GAF_ECursorCode
{
	GAF_CURSOR_UNKNOW		= 0,
	GAF_CURSOR_LEFT,
	GAF_CURSOR_MIDDLE,
	GAF_CURSOR_RIGHT,
	GAF_CURSOR_WHEELUP,
	GAF_CURSOR_WHEELDOWN,
	GAF_CURSOR_X1,
	GAF_CURSOR_X2,

	GAF_CURSOR_MAX,
};

namespace GAF
{
	struct SceenMove
	{
		double			dWay;
		int			nLong;
	};

// 	typedef _VECTOR<SceenMove>	SwingRecord;
	typedef std::vector<SceenMove>	SwingRecord;
#define SwingRecord			std::vector<SceenMove>

	struct DeviceState
	{
		static bool		isInit;					// 初始化状态
		static BYTE		bKeyState[GAF_KEY_MAX / 8 + 1];		// 按键状态
		static BYTE		bCursorState[GAF_CURSOR_MAX / 8 + 1];	// 指针状态
		static Point		atCursorLast;				// 指针之前位置

#ifdef GAF_COMMAND_SCEEN
		// 甩屏
		static bool		isSwing;				// 甩屏的状态
		static Point		atSwingFrist;				// 甩屏的第一点
		static GAF_DTimeTicks	ttSwingFirst;				// 甩屏的开始时间
		static GAF_DTimeTicks	ttSwingLast;				// 甩屏的最后时间
		static SwingRecord	vtrSwingRecord;				// 甩屏的变值记录
#endif /*GAF_COMMAND_SCEEN*/
	};
}
typedef GAF::DeviceState		GAF_SDeviceState;

#define GAF_KEY_STATE			GAF::DeviceState::bKeyState
#define GAF_KEY_DOMARK(_lCode)		GAF_DOMARK(GAF_KEY_STATE[(_lCode) / 8], (_lCode) % 8)
#define GAF_KEY_UNMARK(_lCode)		GAF_UNMARK(GAF_KEY_STATE[(_lCode) / 8], (_lCode) % 8)
#define GAF_KEY_ISMARK(_lCode)		GAF_ISMARK(GAF_KEY_STATE[(_lCode) / 8], (_lCode) % 8)

#define GAF_CURSOR_STATE		GAF::DeviceState::bCursorState
#define GAF_CURSOR_DOMARK(_lCode)	GAF_DOMARK(GAF_CURSOR_STATE[(_lCode) / 8], (_lCode) % 8)
#define GAF_CURSOR_UNMARK(_lCode)	GAF_UNMARK(GAF_CURSOR_STATE[(_lCode) / 8], (_lCode) % 8)
#define GAF_CURSOR_ISMARK(_lCode)	GAF_ISMARK(GAF_CURSOR_STATE[(_lCode) / 8], (_lCode) % 8)



#endif
